package com.lottery.util;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

import com.google.common.collect.Lists;
import com.lottery.pojo.BuyInfoDto;

public class LotteryUtil {

  public static final int REDS_BALL_MIN = 6;

  public static final int BLUES_BALL_MIN = 1;

  private static final List<Integer> REDS_BALL = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
      16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33);
  private static final List<Integer> BLUES_BALL = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
      16);

  private static Random random = new Random(System.currentTimeMillis());
  
  public static BuyInfoDto generateLottery() {
    BuyInfoDto info = new BuyInfoDto();
    info.setReds(getBalls(Lists.newArrayList(REDS_BALL), REDS_BALL_MIN));
    info.setBlues(getBalls(Lists.newArrayList(BLUES_BALL), BLUES_BALL_MIN));
    return info;
  }

  private static List<Integer> getBalls(List<Integer> initBalls, int count) {
    List<Integer> balls = Lists.newArrayList();
    for (int i = 0; i < count; i++) {
      int index = random.nextInt(initBalls.size());
      balls.add(initBalls.get(index));
      initBalls.remove(index);
    }
    return balls;
  }

  public static List<Integer> sortIntegerList(List<Integer> list) {
    Integer[] arrays = new Integer[list.size()];
    arrays = list.toArray(arrays);
    Arrays.sort(arrays);
    return Lists.newArrayList(arrays);
  }

}
